<template>
  <div style="padding: 20px">
    <div class="title_font">
      订单列表
    </div>
  </div>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="120px"
    >
      <el-form-item label="订单号：" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="订单状态：" prop="orderState">
        <el-select
            v-model="queryParams.orderState"
            placeholder="请选择订单状态"
            clearable
            class="!w-240px"
        >
          <el-option
              v-for="dict in getIntDictOptions(DICT_TYPE.ORDERTYPE)"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申请时间" prop="applyTime">
        <el-date-picker
          v-model="queryParams.applyTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="是否智能匹配：" prop="whether">
        <el-select
            v-model="queryParams.whether"
            placeholder="请选择"
            clearable
            class="!w-240px"
        >
          <el-option
              v-for="dict in getIntDictOptions(DICT_TYPE.INTE_MAT_NOT)"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>

      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 查询</el-button>

<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          @click="handleExport"-->
<!--          :loading="exportLoading"-->
<!--          v-hasPermi="['hutai:order:export']"-->
<!--        >-->
<!--          <Icon icon="ep:download" class="mr-5px" /> 导出-->
<!--        </el-button>-->
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" border >
      <el-table-column label="订单号" align="center" prop="orderNo" width="300px" />
      <el-table-column
        label="申请时间"
        align="center"
        prop="applyTime"
        :formatter="dateFormatter"
        width="300px"
      />
      <el-table-column label="申请人" align="center" prop="applyUser" width="200px" />
      <el-table-column label="预估额度" align="center" prop="amount" width="200px" />
      <el-table-column label="实际放款额度" align="center" prop="practicalAmount" width="200px" />
      <el-table-column label="订单状态" align="center" prop="orderState" width="200px">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.ORDERTYPE" :value="scope.row.orderState" />
        </template>
      </el-table-column>
      <el-table-column label="是否智能匹配" align="center" prop="whether" width="200px" >
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.INTE_MAT_NOT" :value="scope.row.whether" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openForm('look', scope.row.id,scope.row.orderNo)"
          >
            详情
          </el-button>

        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

</template>

<script setup lang="ts">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import * as OrderApi from '@/api/hutai/order'
import { useRouter } from "vue-router";
const { push } = useRouter()





defineOptions({ name: 'Order' })

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  orderNo: null,
  applyTime: '',
  amount: null,
  orderState: '',
  whether: '',
  id:''
})
const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {

    const data = await OrderApi.getOrderPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}


const router = useRouter();
/** 添加/修改操作 */
const openForm = (type: string, id: number,orderNo: number) => {
  if (type=='look'){
    push('/guardPage/orderDetails?orderNo='+ orderNo);
    }
}


/** 初始化 **/
onMounted(() => {
  getList()
})

</script>

<style lang="scss">
.title_font{
  margin-bottom: 10px;
  font-size: 16px;
  font-weight: 600;
}
</style>
